/**
 * Querier for getting city rating information about a city
 */
Ext.define('okcapital.layer.querier.CityRatingQuerier', {
    extend: 'portal.layer.querier.Querier',

    datasetStore : null,
    cityStore : null,
    
    constructor: function(config){
        // Call our superclass constructor to complete construction process.
        this.callParent(arguments);
    },

    query : function(queryTarget, callback) {
    	var cityId = queryTarget.get('id');
    	var city = this.cityStore.getById(cityId);
    	
    	var me = this;
        Ext.Ajax.request({
            url : 'getCityRating.do',
            params : {
                cityId : cityId
            },
            callback : function(options, success, response) {
                if (!success) {
                    callback(me, null, queryTarget);
                    return;
                }

                var jsonResponse = Ext.JSON.decode(response.responseText);
                if (!jsonResponse.success) {
                	callback(me, null, queryTarget);
                    return;
                }

                // Load our xml string into DOM, extract the first feature
                var datasetRatings = [];
                for (var i = 0; i < jsonResponse.data.length; i++) {
                	datasetRatings.push(Ext.create('okcapital.model.DatasetRating', jsonResponse.data[i]));
                }
                
                var panel = Ext.create('okcapital.widgets.CityPanel', {
                	datasetStore : me.datasetStore,
                	city : city,
                	datasetRatings : datasetRatings
                });

                callback(me, panel, queryTarget);
            }
        });
    }

});